package com.example.careycai.playactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;

public class PlayFragment extends Fragment {
    private Button btn;
    private TextView tengxun_more;
    private TextView google_more;
    private TextView xunlei_more;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View view = inflater.inflate(R.layout.activity_playactivity, container, false);
        tengxun_more=(TextView) view.findViewById(R.id.tengxun_more);
        google_more=(TextView) view.findViewById(R.id.google_more);
        xunlei_more=(TextView) view.findViewById(R.id.xunlei_more);
        tengxun_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String more="腾讯游戏";
                Intent intent=new Intent(getActivity(),more.class);
                intent.putExtra("more",more);
                startActivity(intent);
            }
        });
        google_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String more="谷歌游戏";
                Intent intent=new Intent(getActivity(),more.class);
                intent.putExtra("more", more);
                startActivity(intent);
            }
        });
        xunlei_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String more="迅雷游戏";
                Intent intent=new Intent(getActivity(),more.class);
                intent.putExtra("more", more);
                startActivity(intent);
            }
        });
        GridView gridview = (GridView)view.findViewById(R.id.GridView);
        GridView gridview2 = (GridView)view.findViewById(R.id.GridView2);
        GridView gridview3 = (GridView)view.findViewById(R.id.GridView3);
        ArrayList<HashMap<String, Object>> meumList = new ArrayList<HashMap<String, Object>>();

        for (int i = 1; i < 5; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("ItemImage", R.drawable.banner);
            map.put("ItemText", "穿越火线CF" + i);
            meumList.add(map);
        }

        SimpleAdapter saMenuItem = new SimpleAdapter(getActivity(),
                meumList, //数据源
                R.layout.item, //xml实现
                new String[]{"ItemImage", "ItemText"}, //对应map的Key
                new int[]{R.id.ItemImage, R.id.ItemText});  //对应R的Id

        //添加Item到网格中
        gridview.setAdapter(saMenuItem);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                                                System.out.println("click index:" + arg2);
                                                int index = arg2 + 1;//id是从0开始的，所以需要+1
                                                Toast.makeText(getActivity(), "你按下了选项：" + index, Toast.LENGTH_SHORT).show();
                                            }
                                        }
        );

        //添加Item到网格中
        gridview2.setAdapter(saMenuItem);
        gridview2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                             public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                                                 System.out.println("click index:" + arg2);
                                                 int index = arg2 + 1;//id是从0开始的，所以需要+1
                                                 Toast.makeText(getActivity(), "你按下了选项：" + index, Toast.LENGTH_SHORT).show();
                                             }
                                         }
        );

        //添加Item到网格中
        gridview3.setAdapter(saMenuItem);
        gridview3.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                             public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                                                 System.out.println("click index:" + arg2);
                                                 int index = arg2 + 1;//id是从0开始的，所以需要+1
                                                 Toast.makeText(getActivity(), "你按下了选项：" + index, Toast.LENGTH_SHORT).show();
                                             }
                                         }
        );
        return  view;
    }


}